﻿// -----------------------------------------------------------------------
// Copyright (c) David Kean. All rights reserved.
// -----------------------------------------------------------------------
extern alias pcl;
using System;
using System.Text;
using System.Globalization;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using pcl::System.Text;

namespace Portable.Text
{
    [TestClass]
    public class StringBuilderExtensionsTests
    {
        [TestMethod]
        public void Clear_NullAsBuilder_ThrowsArgumentNull()
        {
            ExceptionAssert.ThrowsArgumentNull("builder", () =>
            {
                StringBuilderExtensions.Clear((StringBuilder)null);
            });
        }

        [TestMethod]
        public void Clear_WhenLengthIsZero_SetsLengthToZero()
        {
            StringBuilder builder = new StringBuilder();

            var result = StringBuilderExtensions.Clear(builder);

            Assert.AreEqual(0, result.Length);
        }

        [TestMethod]
        public void Clear_WhenLengthIsNonZero_SetsLengthToZero()
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("The quick brown fox jumped over the lazy dog.");

            var result = StringBuilderExtensions.Clear(builder);

            Assert.AreEqual(0, result.Length);
        }

        [TestMethod]
        public void Clear_ReturnsBuilder()
        {
            StringBuilder builder = new StringBuilder();

            var result = StringBuilderExtensions.Clear(builder);

            Assert.AreSame(builder, result);
        }
    }
}
